<?php

namespace api\controllers;

use api\controllers\Controller;
use common\core\actions\GetAction;
use common\core\actions\PostAction;
use common\core\controller\PublicController;
use common\helpers\BaseHelper;


class TestController extends PublicController
{

    public function actions()
    {
        return ['index' => [
            'class' => GetAction::class,
            'data' => function () {
                return 'index function';
            },
        ],
            'update' => [
                'class' => GetAction::class,
                'data' => function () {
                    return 'update function';
                },
            ],
            'del' => [
                'class' => GetAction::class,
                'data' => function () {
                    return 'del function';
                },
            ],
            'curl_info' => [
                'class' => GetAction::class,
                'data' => function ($data) {
                    /* API列表:
                    * http://[device ip]/api/info/all, [GET] 返回当前设备的全部状态
                    * http://[device ip]/api/usb/[usb index, 0|1|2...|9]/[on|off]), [GET] USB电源开关接口
                    * http://[device ip]/api/mb/power/soft, [GET] 短按电源按钮
                    * http://[device ip]/api/mb/power/hard, [GET] 长按电源按钮
                    * http://[device ip]/api/mb/reset, [GET] 硬件复位
                    * http://[device ip]/api/disk/backup, [GET] 磁盘备份
                    * http://[device ip]/api/disk/restore, [GET] 磁盘恢复
                     *
                     */
                    $url = 'http://' . $data['ip'] . '/api/info/all';
                    $url1 = 'http://' . $data['ip'] . '/api/usb/1/off';//USB电源开接口
                    $url2 = 'http://' . $data['ip'] . '/api/usb/1/on';//USB电源关接口
                    $url3 = 'http://'.$data['ip'] . '/api/mb/power/soft';//短按电源按钮
                    $url4 = 'http://'.$data['ip'] . '/api/mb/power/hard';//长按电源按钮
                    $url5 = 'http://'.$data['ip'] . '/api/mb/reset';// 硬件复位
                    $url6 = 'http://'.$data['ip'] . '/api/disk/backup';//磁盘备份
                    $url7 = 'http://'.$data['ip'] . '/api/disk/restore';//磁盘恢复
                    var_dump(BaseHelper::curlGet($url1));
                },
            ]
        ];
    }

}
